//
//  ViewController.m
//  MoviePlayer
//
//  Created by student on 16/4/5.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()<UITabBarDelegate,UITableViewDataSource>
@property(nonatomic,strong) MPMoviePlayerViewController *movievc;
@property(nonatomic,strong) NSMutableArray *mlist;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.mlist=[NSMutableArray array];
    NSArray *arr1=[[NSBundle mainBundle]URLsForResourcesWithExtension:@"3gp" subdirectory:nil];
    NSArray *arr2=[[NSBundle mainBundle]URLsForResourcesWithExtension:@"mv4" subdirectory:nil];
    NSArray *arr3=[[NSBundle mainBundle]URLsForResourcesWithExtension:@"mov" subdirectory:nil];
    [self.mlist addObject:arr1];
    [self.mlist addObject:arr2];
    [self.mlist addObject:arr3];
}
- (IBAction)b:(id)sender
{
    NSURL *fileurl=[[NSBundle mainBundle]URLForResource:@"short" withExtension:@"3gp"];
//    self.movievc=[[MPMoviePlayerViewController alloc]initWithContentURL:fileurl];
//    self.movievc.moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
//    self.movievc.moviePlayer.scalingMode=MPMovieScalingModeFill;
//    [self presentMoviePlayerViewControllerAnimated:self.movievc];
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playdone) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
-(void)playdone
{
    NSLog(@"666");
    [self dismissMoviePlayerViewControllerAnimated];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.mlist.count;
}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
 
     cell.textLabel.text=[NSString stringWithFormat:@"视频:%li",(long)indexPath.row];
 
     return cell;
 }
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    NSString *str=[NSString stringWithFormat:@"%@",self.mlist[indexPath.row]];
     NSLog(@"%@",str);
    NSURL *fileurl=[NSURL URLWithString:str];
    NSURL *url=[NSURL fileURLWithPath:str];
   
    self.movievc=[[MPMoviePlayerViewController alloc]initWithContentURL:url];
    self.movievc.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    self.movievc.moviePlayer.scalingMode = MPMovieScalingModeFill;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playdone) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}

@end
